/*
 * Esse arquivo é parte do Software de Segurança do LaPEC
 * 
 * Copyright (C) 2012-$AnoCorrente$ Dyego Ítallo Silva Ferreira
 * Copyright (C) 2012-$AnoCorrente$ Eduardo Moreira Barbosa
 * Copyright (C) 2012-$AnoCorrente$ João dos Santos Gonçalves
 * 
 * LaPEC é um Software Livre: Você pode redistribuí-lo e/ou modificá-lo
 * de acordo com os termos da Licença Pública Geral GNU (GNU General Public License)
 * conforme publicada pela Free Software Foundation (FSF). Essa permissão é atribuída
 * na versão 3 da Licença, ou (na sua opinião) qualquer versão.
 * 
 * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este programa,
 * se não, escreva para a Fundação do Software Livre(FSF) Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA  02110-1301  USA
 * 
 * Se você tiver alguma dúvida e/ou quiser dar suporte ao desenvolvimento, favor entrar em
 * contato nos e-mails <dyegoitallo@gmail.com>, <barbosa.edrd@gmail.com>, <john.jsg@hotmail.com>.
 */
package gui;

import biometria.Digital;
import conexaoBiometria.ArquivoBinario;
import conexaoBiometria.Leitor;
import dao.mysql.BancoBiometria;
import dao.mysql.BancoDeDadosMySQL;
import dao.mysql.BancoUsuario;
import excecoes.CargoInexistenteException;
import excecoes.DigitalExistenteException;
import java.awt.Dimension;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import usuario.Aluno;
import usuario.Professor;
import usuario.ProfessorResponsavel;
import usuario.Usuario;

/**
 * Interface gráfica do cadastro de usuários
 *
 * @author Dyego Ítallo Silva Ferreira
 */
public class JInternalFrameCadastro extends javax.swing.JInternalFrame implements GUI_JInternalFrame {
    
    // ===============================================================================
    // Variáveis
    // ===============================================================================
    private DefaultListModel modelDigitais;
    private Vector<Integer>  vetorNumDedo;

    // ===============================================================================
    // Construtor
    // ===============================================================================
    public JInternalFrameCadastro() {
        initComponents();
        this.modelDigitais = new DefaultListModel();
        this.vetorNumDedo = new Vector<Integer>();
        // Inicializa a pasta temporária
        //ArquivoBinario.criaTemp();
        //ArquivoBinario.apagarBinarios();
        new ArquivoBinario().carregarArquivoBinario("10112233", 0);
    }

    // ===============================================================================
    // Métodos
    // ===============================================================================
    @Override
    public void setPosicao() {
        Dimension d = this.getDesktopPane().getSize();
        this.setLocation((d.width - this.getSize().width)/2,
                        (d.height - this.getSize().height)/2);
    }
    
    // ===============================================================================
    // Funções
    // ===============================================================================
    /**
     * Função responsável por caputura todos arquivos das digitais e referenciá-los
     * pela classe Digital.
     * @param novoUsuario - Usuário que esta sendo cadastrado.
     * @throws FileNotFoundException - Caso não encontre o arquivo binário que o
     * leitor exporta.
     */
    private void capturaDigitias(Usuario novoUsuario) throws FileNotFoundException {
        Digital novaDigital;
        for (Integer numDigital : this.vetorNumDedo) { 
            novaDigital = new Digital();
            novaDigital.setDedo(new FileInputStream(util.Util.PATHNAME_TEMP + novoUsuario.getMatricula() + "-" + numDigital));
            novaDigital.setNumDedo(numDigital);
            novoUsuario.adicionaDigital(novaDigital);
        }
    }
    /**
     * Saber o cargo do de cadas usuário.
     * @return - Inteiro referente ao cargo do usuário.
     */
    private int cargo() {
        int cargo = 0;
        if (jRadioButtonAluno.isSelected()) {
            cargo = util.Util.ALUNO;
        } else if(jRadioButtonProfessor.isSelected()){
            cargo = util.Util.PROFESSOR;
        } else if(jRadioButtonProfessorResponsavel.isSelected()) {
            cargo = util.Util.PROFESSOR_RESPONSAVEL;
        }
        return cargo;
    }
    /**
     * Responsável por criar um objeto de usuário.
     * @param cargo - Cargo do usuário cadastrado.
     * @return - O objeto Usuario com os dados digitados.
     * @throws CargoInexistenteException - exceção de caso o usuário não tenha cadastrado o cargo.
     */
    private Usuario criaObjetoUsuario(int cargo) throws CargoInexistenteException, FileNotFoundException {
        if(cargo == util.Util.ALUNO) {
            Aluno novoAluno =  new Aluno();
            novoAluno.setMatricula(jTextFieldMatricula.getText().toString());
            novoAluno.setNome     (jTextFieldNome.getText().toString());
            novoAluno.setSenha    (jPasswordSenha.getText().toString());
            capturaDigitias(novoAluno);
            return novoAluno;
        } else if(cargo == util.Util.PROFESSOR) {
            Professor novoProfessor = new Professor();
            novoProfessor.setMatricula(jTextFieldMatricula.getText().toString());
            novoProfessor.setNome     (jTextFieldNome.getText().toString());
            novoProfessor.setSenha    (jPasswordSenha.getText().toString());
            capturaDigitias(novoProfessor);
            return novoProfessor;
        } else if(cargo == util.Util.PROFESSOR_RESPONSAVEL) {
            ProfessorResponsavel novoProfessorResp = new ProfessorResponsavel();
            novoProfessorResp.setMatricula(jTextFieldMatricula.getText().toString());
            novoProfessorResp.setNome     (jTextFieldNome.getText().toString());
            novoProfessorResp.setSenha    (jPasswordSenha.getText().toString());
            capturaDigitias(novoProfessorResp);
            return novoProfessorResp;
        } else {
            throw new CargoInexistenteException();
        }

    }
    /**
     * Cadastra um novo usuário no banco de dados.
     */
    private void cadastrarUsuario() {
        try {
            int cargo = cargo();
            Usuario novoUsuario = criaObjetoUsuario(cargo);
            
            BancoDeDadosMySQL bd = new BancoDeDadosMySQL();
            bd.conectarBanco();
    
            BancoUsuario bdUsuario = new BancoUsuario();
            bdUsuario.cadastrarUsuario(novoUsuario, cargo);
            BancoBiometria bdBiometria = new BancoBiometria();
            bdBiometria.cadastrarBiometria(novoUsuario);
            
            JOptionPane.showMessageDialog(null, "Usuário cadastrado com sucesso!");
            this.setVisible(false);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(JInternalFrameCadastro.class.getName()).log(Level.SEVERE, null, ex);
        } catch (CargoInexistenteException cie) {
            JOptionPane.showMessageDialog(null, cie.getMessage());
        }
    }
    /**
     * Aciona o leitor biométrico para coletar e exportar uma digial.
     */
    private void adicionarDigital() throws IOException, InterruptedException, DigitalExistenteException {
        String matricula;
        int dedo;
        matricula = jTextFieldMatricula.getText();
        dedo = jComboBoxDedos.getSelectedIndex();
        contemListDigitais(jComboBoxDedos.getItemAt(dedo).toString());
        Leitor leitor = new Leitor();
        leitor.iniciaLeitor(matricula, dedo);
        leitor.atualizaDadosLeitor();
        while (!leitor.isStatus()) {
            leitor.atualizaDadosLeitor();
            Thread.sleep(50);
            System.out.println("Porcentagem: " + leitor.getPorcentagem());
            if (leitor.getErro() != null) {
                //JOptionPane.showMessageDialog(null, "fdsfas");
                jLabelErro.setText("ERRO:");
                jLabelTipoErro.setText(leitor.getErro());
                System.out.println(jLabelTipoErro.getText() + " " + jLabelTipoErro.getText());
            } else {
                jLabelErro.setText("");
                jLabelTipoErro.setText("");
                System.out.println(jLabelTipoErro.getText() + " " + jLabelTipoErro.getText());
            }
        }
        this.vetorNumDedo.add(dedo);
        addListDigitais(jComboBoxDedos.getItemAt(dedo).toString());
        JOptionPane.showMessageDialog(null, "Dedo " + jComboBoxDedos.getItemAt(dedo).toString()
                + " adicionado com sucesso");
    }

    /**
     * Adiciona as digitais no jListDigitias
     *
     * @param digital - Nome da digital que será adicionada ao jListDigitais
     */
    private void addListDigitais(String digital) {
        modelDigitais.addElement(digital);
        jListDigitais.setModel(modelDigitais);
    }
    
    /**
     * Verifica se a digital já foi cadastrada.
     * @param digital - String do nome da digital dada pelo jListDigitais.
     * @throws DigitalExistenteException - Lança a exceção caso a digital já
     * esteja cadastrada.
     */
    private void contemListDigitais(String digital) throws DigitalExistenteException {
        for (int x = 0; x < modelDigitais.getSize(); x++) {
            if (modelDigitais.getElementAt(x).toString().equals(digital)) {
                throw new DigitalExistenteException();
            }
        }
    }

    // ===============================================================================
    // Código gerado automáticamente
    // ===============================================================================
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroupCargo = new javax.swing.ButtonGroup();
        jPanelNome = new javax.swing.JPanel();
        jLabelNome = new javax.swing.JLabel();
        jTextFieldNome = new javax.swing.JTextField();
        jLabelMatricula = new javax.swing.JLabel();
        jLabelSenha = new javax.swing.JLabel();
        jPasswordSenha = new javax.swing.JPasswordField();
        jTextFieldMatricula = new javax.swing.JTextField();
        jButtonOK = new javax.swing.JButton();
        jPanelDigital = new javax.swing.JPanel();
        jButtonAlterar = new javax.swing.JButton();
        jButtonRemover = new javax.swing.JButton();
        jComboBoxDedos = new javax.swing.JComboBox();
        jScrollPaneDigitaisCadastradas = new javax.swing.JScrollPane();
        jListDigitais = new javax.swing.JList();
        jButtonAdicionar = new javax.swing.JButton();
        jPanelCargo = new javax.swing.JPanel();
        jRadioButtonProfessor = new javax.swing.JRadioButton();
        jRadioButtonProfessorResponsavel = new javax.swing.JRadioButton();
        jRadioButtonAluno = new javax.swing.JRadioButton();
        jButtonCancelar = new javax.swing.JButton();
        jLabelErro = new javax.swing.JLabel();
        jLabelTipoErro = new javax.swing.JLabel();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setTitle("LaPeC - Cadastro");

        jPanelNome.setBorder(javax.swing.BorderFactory.createTitledBorder("Nome"));

        jLabelNome.setText("Nome:");

        jLabelMatricula.setText("Matricula:");

        jLabelSenha.setText("Senha:");

        javax.swing.GroupLayout jPanelNomeLayout = new javax.swing.GroupLayout(jPanelNome);
        jPanelNome.setLayout(jPanelNomeLayout);
        jPanelNomeLayout.setHorizontalGroup(
            jPanelNomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelNomeLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelNomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabelMatricula)
                    .addComponent(jLabelNome))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelNomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanelNomeLayout.createSequentialGroup()
                        .addComponent(jTextFieldMatricula)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabelSenha)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPasswordSenha, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jTextFieldNome, javax.swing.GroupLayout.PREFERRED_SIZE, 339, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelNomeLayout.setVerticalGroup(
            jPanelNomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelNomeLayout.createSequentialGroup()
                .addGroup(jPanelNomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelNome)
                    .addComponent(jTextFieldNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelNomeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelMatricula)
                    .addComponent(jLabelSenha)
                    .addComponent(jPasswordSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButtonOK.setText("OK");
        jButtonOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOKActionPerformed(evt);
            }
        });

        jPanelDigital.setBorder(javax.swing.BorderFactory.createTitledBorder("Digitais"));

        jButtonAlterar.setText("Alterar");
        jButtonAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAlterarActionPerformed(evt);
            }
        });

        jButtonRemover.setText("Remover");

        jComboBoxDedos.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Indicador direito", "Indicador esquerdo", "Médio direito", "Médio esquerdo", "Anelar direito", "Anelar esquerdo", "Mínimo direito", "Mínimo esquerdo", "Polegar direito", "Polegar esquerdo" }));

        jScrollPaneDigitaisCadastradas.setViewportView(jListDigitais);

        jButtonAdicionar.setText("Adicionar");
        jButtonAdicionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAdicionarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelDigitalLayout = new javax.swing.GroupLayout(jPanelDigital);
        jPanelDigital.setLayout(jPanelDigitalLayout);
        jPanelDigitalLayout.setHorizontalGroup(
            jPanelDigitalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDigitalLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelDigitalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelDigitalLayout.createSequentialGroup()
                        .addComponent(jScrollPaneDigitaisCadastradas, javax.swing.GroupLayout.PREFERRED_SIZE, 345, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelDigitalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButtonAlterar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonRemover, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonAdicionar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jComboBoxDedos, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanelDigitalLayout.setVerticalGroup(
            jPanelDigitalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDigitalLayout.createSequentialGroup()
                .addComponent(jComboBoxDedos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDigitalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelDigitalLayout.createSequentialGroup()
                        .addComponent(jButtonAdicionar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonAlterar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonRemover)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jScrollPaneDigitaisCadastradas, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addContainerGap())
        );

        jPanelCargo.setBorder(javax.swing.BorderFactory.createTitledBorder("Cargo"));

        buttonGroupCargo.add(jRadioButtonProfessor);
        jRadioButtonProfessor.setText("Professor");
        jRadioButtonProfessor.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));

        buttonGroupCargo.add(jRadioButtonProfessorResponsavel);
        jRadioButtonProfessorResponsavel.setText("Professor responsável");
        jRadioButtonProfessorResponsavel.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));

        buttonGroupCargo.add(jRadioButtonAluno);
        jRadioButtonAluno.setText("Aluno");
        jRadioButtonAluno.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));

        javax.swing.GroupLayout jPanelCargoLayout = new javax.swing.GroupLayout(jPanelCargo);
        jPanelCargo.setLayout(jPanelCargoLayout);
        jPanelCargoLayout.setHorizontalGroup(
            jPanelCargoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelCargoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jRadioButtonAluno)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButtonProfessor)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButtonProfessorResponsavel)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelCargoLayout.setVerticalGroup(
            jPanelCargoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelCargoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jRadioButtonProfessor)
                .addComponent(jRadioButtonProfessorResponsavel)
                .addComponent(jRadioButtonAluno))
        );

        jButtonCancelar.setText("Cancelar");
        jButtonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarActionPerformed(evt);
            }
        });

        jLabelErro.setText("Erro:");

        jLabelTipoErro.setText("Passe o dedo devagar!");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanelDigital, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanelNome, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanelCargo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabelErro)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabelTipoErro)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButtonOK, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelDigital, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelCargo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonOK)
                    .addComponent(jButtonCancelar)
                    .addComponent(jLabelErro)
                    .addComponent(jLabelTipoErro))
                .addContainerGap(24, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // ===============================================================================
    // Eventos
    // ===============================================================================
    private void jButtonAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAlterarActionPerformed
        
    }//GEN-LAST:event_jButtonAlterarActionPerformed

    private void jButtonAdicionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAdicionarActionPerformed
        try {
            adicionarDigital();
        } catch (DigitalExistenteException dee) {
            JOptionPane.showMessageDialog(null, dee.getMessage());
        } catch (IOException ex) {
            System.out.println("Erro");
        } catch (InterruptedException ex) {
            System.out.println("Erro");
        }
    }//GEN-LAST:event_jButtonAdicionarActionPerformed

    private void jButtonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelarActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_jButtonCancelarActionPerformed

    private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
        //capturaDigitias();
        cadastrarUsuario();
    }//GEN-LAST:event_jButtonOKActionPerformed

    // ===============================================================================
    // Váriáveis geradas automáticamente
    // ===============================================================================
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroupCargo;
    private javax.swing.JButton jButtonAdicionar;
    private javax.swing.JButton jButtonAlterar;
    private javax.swing.JButton jButtonCancelar;
    private javax.swing.JButton jButtonOK;
    private javax.swing.JButton jButtonRemover;
    private javax.swing.JComboBox jComboBoxDedos;
    private javax.swing.JLabel jLabelErro;
    private javax.swing.JLabel jLabelMatricula;
    private javax.swing.JLabel jLabelNome;
    private javax.swing.JLabel jLabelSenha;
    private javax.swing.JLabel jLabelTipoErro;
    private javax.swing.JList jListDigitais;
    private javax.swing.JPanel jPanelCargo;
    private javax.swing.JPanel jPanelDigital;
    private javax.swing.JPanel jPanelNome;
    private javax.swing.JPasswordField jPasswordSenha;
    private javax.swing.JRadioButton jRadioButtonAluno;
    private javax.swing.JRadioButton jRadioButtonProfessor;
    private javax.swing.JRadioButton jRadioButtonProfessorResponsavel;
    private javax.swing.JScrollPane jScrollPaneDigitaisCadastradas;
    private javax.swing.JTextField jTextFieldMatricula;
    private javax.swing.JTextField jTextFieldNome;
    // End of variables declaration//GEN-END:variables
}
